#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, sys
import typing

from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
    
    PROJECT_ROOT: str = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    BASE_DIR: str = os.path.abspath(os.path.join(PROJECT_ROOT, os.pardir))
    
    model_config = SettingsConfigDict(env_file=f'{PROJECT_ROOT}/.env', env_file_encoding='utf-8', extra='ignore')
    
    VERSION: str = "0.1.0"
    APP_TITLE: str = "python api framework"
    PROJECT_NAME: str = "Robyn"
    APP_DESCRIPTION: str = "Description"
    ROBYN_API_V1_PATH: str = '/api/v1'
    ROBYN_DOCS_URL: str | None = f'{ROBYN_API_V1_PATH}/docs'

    CORS_ORIGINS: typing.List = ["*"]
    CORS_ALLOW_CREDENTIALS: bool = True
    CORS_ALLOW_METHODS: typing.List = ["*"]
    CORS_ALLOW_HEADERS: typing.List = ["*"]
    
    # Env Config
    ENVIRONMENT: typing.Literal['dev', 'pro']
    
    BACKEND_HOST: str
    BACKEND_PORT: int
    
    # Env DATABASE
    DATABASE_HOST: str
    DATABASE_PORT: int
    DATABASE_USER: str
    DATABASE_PASSWORD: str
    DATABASE_POOL_SIZE: int
    
    DATABASE_ECHO: bool
    DATABASE_NAME: str
    DATABASE_CHARSET: str
    
    ENABLE_DB: bool
    
    # Http 请求超时时间
    REQUEST_TIME_OUT: int = 30
    
    FORMAT_LOG: bool
    # 日志目录
    LOG_ERROR_DIR: str = os.path.join(BASE_DIR, "log", "error", "error.log")
    LOG_INFO_DIR: str = os.path.join(BASE_DIR, "log", "info", "info.log")

settings = Settings()